import load from '../../templates/loader/loader.js'
import api from '../../../api/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arrayData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    //初始化载入等待动画
    that.loader = load.loader(that, {
      data: "loader",
      borderWidth: 1
    });
    var jsonStr = '{"REQ_HEAD":{"SIGN":"null"},"REQ_BODY":{"goodsId":' + options.goodsId + ',"shop_series":"' + options.shop_series + '","pageNo":' + 1 + ',"pageSize":' + 100 + '}}'
    that.loader.open()
    api.getrecommend({
      method: 'POST',
      data: {
        REQ_MESSAGE: jsonStr
      },
      complete: (res) => {
        that.loader.close(); //关闭载入动画
        console.log(res)
        var data = res.data.rows;
        switch (res.statusCode) {
          case 200:
            if (data) {
              if (data.length <= 0) {
                that.loader.open("没有更多了");
              } else {
                that.setData({
                  arrayData: data
                })
              }
            } else {
              that.loader.open("没有更多了");
            }
            break;
          case 404:
            that.loader.open(api.status404.title);
            break;
          case 500:
            that.loader.open(api.status500.title);
            break;
          default:
            that.loader.open(api.statusUnknown.title);
            break;
        }
      },
      fail: (res) => {
        that.loader.open(api.statusFail.title);
      }
    });
  }
})